package com.senken.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.senken.mapper.DeclaresMapper;
import com.senken.commons.entity.FidStateAndPage;
import com.senken.entity.Declares;
import com.senken.service.IDeclaresService;
import com.senken.service.ISkWoService;
import com.senken.util.CreateWo;
import com.baomidou.framework.service.impl.SuperServiceImpl;

/**
 *
 * Declares 表数据服务层接口实现类
 *
 */
@Service
public class DeclaresServiceImpl extends SuperServiceImpl<DeclaresMapper, Declares> implements IDeclaresService {


	@Autowired
	private DeclaresMapper declaremapper;
	@Autowired
	private ISkWoService service;
	
	@Override
	public List<Declares> selectdeclare(){
		return declaremapper.selectdeclare();
	}
	public static final int NUM=10;
	/**
	 * 添加维修记录
	 */
	@Override
	public Declares addDeclares(String customer,String name,String phone,String device,String code,int num,String des,String way){
		Declares declares = new Declares();
		declares.setCustomer(customer);
		declares.setName(name);
		declares.setCode(code);
		declares.setDes(des);
		declares.setDevice(device);
		declares.setNumber(num);
		declares.setWay(way);
		declares.setPhone(phone);
		declares.setStartime(new Date());
		this.insert(declares);
		return declares;
	}
	
	/**
	 * 查找维修记录
	 */
	@Override
	public List<Declares> selectdeclareByFid(int fid,int state,int page){
		FidStateAndPage fidStateAndPage = new FidStateAndPage();
		fidStateAndPage.setFid(fid);
		fidStateAndPage.setState(state);
		fidStateAndPage.setNum(NUM);
		fidStateAndPage.setStart((page-1)*NUM);
		return declaremapper.selectdeclaresByfidStateAndPage(fidStateAndPage);
	}
	/**
	 * 查找维修类型
	 */
	@Override
	public List<Declares> selectdeclareByState(int fid,int state,int page){
		FidStateAndPage fidStateAndPage = new FidStateAndPage();
		fidStateAndPage.setFid(fid);
		fidStateAndPage.setState(state);
		fidStateAndPage.setNum(NUM);
		fidStateAndPage.setStart((page-1)*NUM);
		return declaremapper.selectdeclaresByState(fidStateAndPage);
	}
	/**
	 * 通用查询次数
	 */
	@Override
	public int selectCountsByfidStateAndPage(int fid,int state){
		FidStateAndPage fidStateAndPage = new FidStateAndPage();
		fidStateAndPage.setFid(fid);
		fidStateAndPage.setState(state);
		return declaremapper.selectcountsByfidStateAndPage(fidStateAndPage);
	}
	
	@Override
	public boolean createWo(int Hid){
		Declares declares = new Declares();
		declares.setHid(Hid);
		declares = this.selectOne(declares);
		System.out.println(declares.getCustomer());
		declares.setWo(CreateWo.Createwo(service));
		return this.updateById(declares);
	}
	
	@Override
	public boolean finish(int hid,String solution){
		Declares declares = new Declares();
		declares.setHid(hid);
		declares = this.selectOne(declares);
		declares.setEndtime(new Date());
		declares.setSolution(solution);
		return this.updateById(declares);
	}
	
	@Override 
	public int finishcounts(int state){
		return declaremapper.finishcount(state);
	}
	
	@Override
	public List<Declares> selectfinish(int state,int page){
		FidStateAndPage fidStateAndPage = new FidStateAndPage();
		fidStateAndPage.setState(state);
		fidStateAndPage.setNum(NUM);
		fidStateAndPage.setStart((page-1)*NUM);
		return this.declaremapper.selectfinish(fidStateAndPage);
		
	}
}
















